package com.xiaotu.dao;

import com.xiaotu.model.TabEnterpriseRentApplyInfo;
import com.xiaotu.model.TabEnterpriseRentInfo;
import com.xiaotu.model.TabEnterpriseRentInfoDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * @作者 王艳龙
 * @日期 2021-03-10 17:08
 * @功能
 */
public interface RentInfoDao extends Mapper<TabEnterpriseRentInfo> {

    /**
     * 获取企业房租通基本信息列表
     * @param applyId
     * @return
     */
    @Select("<script>"
            + "SELECT"
            + "  *  "
            + "FROM "
            + "  tab_enterprise_rent_info where 1=1 "
            + "<if test='applyId !=null and applyId !=\"\" '>"
            + " and apply_id=#{applyId} "
            + "</if>"
            +"</script>")
    public TabEnterpriseRentInfo queryRentInfo(@Param("applyId") Integer applyId);


    /**
     * 获取所属园区名称
     * @param enterpriseParkId
     * @return
     */
    @Select("SELECT"
            + "  enterprise_id AS enterpriseParkId,  "
            + "  enterprise_name AS enterpriseParkName "
            + "FROM "
            + "  tab_enterprise_user "
            + " where enterprise_type_level1_id =5 "
            + " and area_id=#{enterpriseParkId} order by enterprise_id ")
    public List<Map<String,Object>> queryEnterpriseParkName(@Param("enterpriseParkId") String enterpriseParkId);

    /**
     * 根据申请获取房租通基本信息
     * @param applyId
     * @return
     */
    @Select("SELECT"
            + "  teri.*, terc.dsr_name AS actual_contro,terc.contact_name,  "
            + "  terc.contact_position,terc.contact_email,terc.contact_phone "
            + "FROM "
            + "  tab_enterprise_rent_info teri "
            + "LEFT JOIN tab_enterprise_rent_contacts_info terc ON teri.apply_id = terc.apply_id "
            + " where teri.apply_id=#{applyId} ")
    public TabEnterpriseRentInfoDto queryRentInfoByApplId(String applyId);

    /**
     * 根据企业id获取企业一级分类
     * @param enterpriseId
     * @return
     */
    @Select(" SELECT"
            + "  enterprise_type_level1_id AS enterpriseType  "
            + " FROM "
            + "  tab_enterprise_user "
            + " where enterprise_id=#{enterpriseId} ")
    public Map<String,Object> queryEnterpriseLevelId(@Param("enterpriseId") String enterpriseId);

    /**
     * 修改企业用户信息
     * @param model
     * @param enterpriseId
     */
    @Update(" update tab_enterprise_user set enterprise_name=#{model.enterpriseName},province_id=#{model.provinceId}, " +
            " city_id=#{model.cityId},area_id=#{model.areaId},enterprise_type_level3_id=#{model.enterpriseTypeLevel3Id}, " +
            "enterprise_park_id=#{model.enterpriseParkId}, " +
            " credit_code=#{model.creditCode} " +
            " where enterprise_id=#{enterpriseId} ")
    public void updateEnterpriseUserInfo(@Param("model") TabEnterpriseRentInfoDto model,@Param("enterpriseId") String enterpriseId);

    /**
     * 修改企业文化信息
     * @param model
     * @param enterpriseId
     */
    @Update(" update tab_enterprise_wh_info set establish_date=#{model.establishDate},legal_representative=#{model.legalRepresentative}," +
            " registered_capital=#{model.registeredCapital},company_type=#{model.companyType},registered_address=#{model.registeredAddress}," +
            " main_office_address=#{model.mainOfficeAddress},enterprise_classification=#{model.enterpriseClassification},staffs=#{model.staffs}," +
            " website_address=#{model.websiteAddress},business_scope=#{model.businessScope},actual_contro=#{model.actualContro}," +
            " contact_name=#{model.contactName},contact_position=#{model.contactPosition},contact_email=#{model.contactEmail}," +
            " contact_phone=#{model.contactPhone} where enterprise_id=#{enterpriseId} ")
    public void updateEnterpriseWhInfo(@Param("model") TabEnterpriseRentInfoDto model,@Param("enterpriseId") String enterpriseId);

    /**
     * //股权投资机构\金融机构\服务机构信息
     * @param model
     * @param enterpriseId
     * @param tableName
     */
    @Update(" update ${tableName} set establish_date=#{model.establishDate},legal_representative=#{model.legalRepresentative}," +
            " registered_capital=#{model.registeredCapital},registered_address=#{model.registeredAddress},main_office_address=#{model.mainOfficeAddress}," +
            " staffs=#{model.staffs},website_address=#{model.websiteAddress},business_scope=#{model.businessScope},contact_name=#{model.contactName}," +
            " contact_position=#{model.contactPosition},contact_email=#{model.contactEmail},contact_phone=#{model.contactPhone} " +
            " where enterprise_id=#{enterpriseId} ")
    public void updateEnterpriseXInfo(@Param("model") TabEnterpriseRentInfoDto model,@Param("enterpriseId") String enterpriseId,@Param("tableName") String tableName);

    /**
     * 修改企业园区信息
     * @param model
     * @param enterpriseId
     */
    @Update(" update tab_enterprise_yq_info set legal_representative=#{model.legalRepresentative}," +
            " registered_capital=#{model.registeredCapital},registered_address=#{model.registeredAddress}," +
            " website_address=#{model.websiteAddress},business_scope=#{model.businessScope}," +
            " contact_name=#{model.contactName},contact_position=#{model.contactPosition}," +
            " contact_email=#{model.contactEmail},contact_phone=#{model.contactPhone} " +
            " where enterprise_id=#{enterpriseId} ")
    public void updateEnterpriseYqInfo(@Param("model") TabEnterpriseRentInfoDto model,@Param("enterpriseId") String enterpriseId);

}
